package com.csx.saas.platform.system.enumeration;

import com.csx.basic.base.BaseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.stream.Stream;

/**
 * <p>
 * 实体注释中生成的类型枚举
 * 角色
 * </p>
 *
 * @author ChenSongXin
 * @date 2021-02-28
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "DataScopeType", description = "数据权限-枚举")
public enum DataScopeType implements BaseEnum {

    /**
     * ALL=1全部
     */
    ALL(1,"全部"),
    /**
     * THIS_LEVEL=2本级
     */
    THIS_LEVEL(2,"本级"),
    /**
     * THIS_LEVEL_CHILDREN=3本级以及子级
     */
    THIS_LEVEL_CHILDREN(3,"本级以及子级"),
    /**
     * CUSTOMIZE=4自定义
     */
    CUSTOMIZE(4,"自定义"),
    /**
     * SELF=5个人
     */
    SELF(5,"个人"),
    ;

    @ApiModelProperty(value = "描述")
    private int val;

    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static DataScopeType match(String val, DataScopeType def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static DataScopeType get(String val) {
        return match(val, null);
    }

    public boolean eq(DataScopeType val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "ALL,THIS_LEVEL,THIS_LEVEL_CHILDREN,CUSTOMIZE,SELF", example = "ALL")
    public String getCode() {
        return this.name();
    }

}
